﻿@using si.caha.Model;
@using si.caha.Repository;

@{
    Layout = "/tpl/_layout.cshtml";
    PageData["PageTitle"] = "Items list";

    var dataContext = new DataContext();
    var itemRepository = new ItemRepository(dataContext);
    var grid = new WebGrid(itemRepository.GetAll(), ajaxUpdateContainerId: "grid");

    // FML -> do delete
    if (IsPost)
    {
        for (int i = 0; i < 10; i++)
        {
            var item = new Item();
            item.Title = "Title " + i;
            item.CategoryId = 1;
            itemRepository.Save(item);
        }
    }    
}
<div id="grid">
    @grid.GetHtml(
        tableStyle: "grid",
        headerStyle: "gridhead",
        alternatingRowStyle: "altRow",
        columns: grid.Columns(
            grid.Column("Title"),
            grid.Column("Description"),
            grid.Column("Price", format:@<i>€@item.Price</i>),
            grid.Column("Images #", format:@<i>@item.Images.Count</i>),
            grid.Column("", format:@<a href="@Href("~/Admin/Items/Delete/" + @item.ItemId)">Delete</a>),
            grid.Column("", format:@<a href="@Href("~/Admin/Items/Edit/" + @item.ItemId)">Edit</a>)
        )
    )
</div>
<a href="@Href("~/Admin/Items/Create")">Create item</a>
<form method="post">
    <button type="submit" id="submit">FML!</button>
</form>